home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / gnu / gnumake / pdmake.zoo / gemstart.s < prev    next >
Text File  |  1991-09-25  |  4KB  |  170 lines

  1. ******************************************************************************
  2. *
  3. *    C runtime startup for CP/M-68k.
  4. *
  5. *    Adapted for make (no AES control array, 12k stack)
  6. *
  7. ******************************************************************************
  8. *
  9. ltpa=0            * Low TPA address
  10. htpa=4            * High TPA address
  11. lcode=8            * Code segment start
  12. codelen=12        * Code segment length
  13. ldata=16        * Data segment start
  14. datalen=20        * Data segment length
  15. lbss=24            * Bss  segment start
  16. bsslen=28        * Bss  segment length
  17. freelen=32        * free segment length
  18. resvd=36        * Reserved
  19. fcb2=56            * 2nd parsed fcb
  20. fcb1=92            * 1st parsed fcb
  21. command=128        * Command tail
  22. prtstr=9        * Print string BDOS Call
  23. exit=0            * BDOS exit call
  24. .globl    __main
  25. .globl    __exit
  26. .globl    __break
  27. .globl    ___cpmrv
  28. .globl    __base
  29. .globl  _sw_
  30. .globl    __sovf
  31.  
  32.  
  33.         .text
  34.  
  35.  
  36. *
  37. *  Must be first object file in link statement
  38. *
  39.     move.l    a7,a5        * save a7 so we can get the base page address
  40.     move.l    4(a5),a5    * a5=basepage address
  41.     move.l    a5,__base    * save for C startup
  42.     move.l    $c(a5),d0
  43.     add.l    $14(a5),d0
  44.     add.l    $1c(a5),d0
  45.     add.l    #$3100,d0    * d0=basepage+textlen+datalen+bsslen
  46. *                  (plus 12K of user stack)
  47.     move.l    d0,d1
  48.     add.l    a5,d1        * compute stack top
  49.     and.l    #-2,d1        * ensure even byte boundary
  50.     move.l    d1,a7        * setup user stack, 1K above end of BSS
  51.  
  52.     move.l    d0,-(sp)
  53.     move.l    a5,-(sp)
  54.     clr.w    -(sp)        * junk word
  55.     move    #$4a,-(sp)    * return excess storage
  56.     trap    #1
  57.     add.l    #12,sp
  58.  
  59.  
  60.         move.l    __base,a0        *    Load C external
  61.         move.l    lbss(a0),a1        *    a1 -> bss region
  62.         adda.l    bsslen(a0),a1        *    a1 -> 1st heap loc
  63.  
  64.         move.l    a1,__break        *    Put in "break" loc
  65.         lea.l    command(a0),a2        *    a2 -> command line
  66.         move.b    (a2)+,d0        *    d0 = byte count
  67.         andi.l    #$ff,d0            *    clear junk
  68.         move.w    d0,-(a7)        *    push length
  69.         move.l    a2,-(a7)        *    Push commnd
  70.         clr.l    a6            *    Clear frame pointer
  71.         jsr    __main            *    call main routine
  72.         jmp    __exit            *    call "exit"
  73.  
  74.  
  75.     .bss
  76.     .even
  77. __base:        .ds.l    1            *    -> Base Page
  78. __break:    .ds.l    1            *    Break function
  79. ___cpmrv:    .ds.w    1            *    Last CP/M return val
  80.  
  81.  
  82.  
  83. *
  84. *
  85. .globl    _brk
  86.         .text
  87. _brk:        
  88.         movea.l    4(sp),a0        *    New break?
  89.         move.l     a0,d0
  90.         lea    $100(a0),a0        *    Chicken factor
  91.         cmpa.l    a0,sp            *    Compare
  92.         bhis    brkok            *    OK, continue
  93.         move.l    #-1,d0            *    Load return reg
  94.         rts                *    Return
  95. brkok:
  96.         move.l    d0,__break        *    Save the break
  97.         clr.l    d0            *    Set OK return
  98.         rts                *    return
  99.         
  100. .globl    ___BDOS
  101. ___BDOS:    link    a6,#0            *    link
  102.         move.w    8(sp),d0        *    Load func code
  103.         move.l    10(sp),d1        *    Load Paramter
  104.         trap    #2            *    Enter BDOS
  105.         cmpa.l    __break,sp        *    Check for stack ovf
  106.         bhis    noovf            *    NO overflow, continue
  107. __sovf:        move.w    #prtstr,d0        *    String print
  108.         lea    ovf,a0            *    a0-> message
  109.         move.l    a0,d1            *    load proper reg
  110.         trap    #2            *    Issue message
  111. __exit:        move.w    #exit,d0        *    Exit
  112.         trap    #2            *        now
  113. noovf:                        *    Here if all OK
  114.         unlk    a6            *
  115.         rts                *    Back to caller
  116. *
  117. *    Block Fill function:
  118. *
  119. *    blkfill(dest,char,cnt);
  120. *
  121. *    BYTE    *dest;        /* -> area to be filled    */
  122. *    BYTE    char;        /* =  char to fill    */
  123. *    WORD    cnt;        /* =  # bytes to fill   */
  124. *
  125.     .globl    _blkfill
  126. _blkfill:
  127.     move.l    4(a7),a0            *    -> Output area
  128.     move.w    8(a7),d1            *    =  output char
  129.     move.w    10(a7),d0            *    =  output count
  130.     ext.l    d0                *    make it long
  131.     subq.l    #1,d0                *    decrement
  132.     ble    filldone            *    Done if le
  133. fillit:    move.b    d1,(a0)+            *    move a byte
  134.     dbra    d0,fillit            *    Continue
  135. filldone: clr.l    d0                *    always return 0
  136.     rts                    *
  137.  
  138. *
  139. *    Index function to find out if a particular character is in a string.
  140. *
  141.     .globl    _index
  142.     .globl    _strchr
  143. _index:
  144. _strchr:
  145.     move.l    4(a7),a0            *    a0 -> String
  146.     move.w    8(a7),d0            *    D0 = desired character
  147. xindex:    tst.b    (a0)                *    EOS?
  148.     bne    notend                *    No, continue to look
  149.     clr.l    d0                *    Not found
  150.     rts                    *    Quit
  151. notend:    cmp.b    (a0)+,d0            *    check for character
  152.     bne    xindex                *    
  153.     move.l    a0,d0                *    Found it
  154.     subq.l    #1,d0                *    set return pointer
  155.     rts                    *
  156. *
  157. *    Data area
  158. *
  159.         .data
  160.         .globl    ___pname        *    Program Name
  161.         .globl    ___tname        *    Terminal Name
  162.         .globl    ___lname        *    List device name
  163.         .globl    ___xeof            *    ^Z byte
  164. ovf:        .dc.b    'Stack Overflow$'    *    Error message
  165. ___pname:    .dc.b    'C runtime',0        *    Program name
  166. ___tname:    .dc.b    'CON:',0        *    Console name
  167. ___lname:    .dc.b    'LST:',0        *    List device name
  168. ___xeof:    .dc.b    $1a            *    Control-Z
  169.         .end
  170.